package com.fyyg.monitor.job;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.alibaba.dubbo.config.annotation.Reference;
import com.alibaba.fastjson.JSONObject;
import com.fyyg.common.util.popular.util.AccessToken;
import com.fyyg.common.util.popular.util.HttpRequest;
//import com.fyyg.interfaces.system.TBusiWhechatConfigService;

public class WechatConfigUpdateJob {

	private final static Logger logger = LogManager.getLogger(WechatConfigUpdateJob.class);
	 
//	@Reference 
//	TBusiWhechatConfigService whechatConfigService;

    public WechatConfigUpdateJob(){
        logger.info("WechatConfigUpdateJob start...");
    }
    
    public void execute(){
        logger.info("WechatConfigUpdateJob execute ..... ");
        String token  = AccessToken.getAccessToken();
        String ticket = AccessToken.getJsTicket(token);

//        TBusiWechatConfig config =  whechatConfigService.selectByPrimaryKey(1);
//    	config.setAccesstoken(token);
//    	config.setJsticket(ticket);
//    	whechatConfigService.updateByPrimaryKeySelective(config);
        logger.info("WechatConfigUpdateJob execute end ");
    }
    
    public static void main(String[] args) {
    	String url ="https://api.weixin.qq.com/cgi-bin/token";
		String param ="grant_type=client_credential&appid=wxf438f36b6faf41de&secret=d34ec8d38f97603a54dc8636f94b69d1";
		HttpRequest httpre = new HttpRequest();
		String result = httpre.sendPost(url, param);
    	JSONObject json = JSONObject.parseObject(result);
		String token = json.getString("access_token");
		System.out.println(token);
		
		 String url2 = "https://api.weixin.qq.com/cgi-bin/ticket/getticket";  
         String param2 ="access_token=" + token + "&type=jsapi";
		 HttpRequest httpre2 = new HttpRequest();
		 String result2 = httpre2.sendPost(url2, param2);
    	 JSONObject json2 = JSONObject.parseObject(result2);
    	 System.out.println(json2.getString("ticket"));
    	
    	
	}
}
